package com.newcoin.chat.beans;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.websocket.EncodeException;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;
import java.util.List;

/**
 * WebSocket List编码类
 */
public class EncoderClassVo implements Encoder.Text<List> {
    @Override
    public String encode(List list) throws EncodeException {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            String json = "";
            json = objectMapper.writeValueAsString(list);
            return json;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public void init(EndpointConfig endpointConfig) {

    }

    @Override
    public void destroy() {

    }
}
